package com.intct;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

/**
 * @author gufg
 * @since 2025-11-07 09:30
 */
public class JdbcTest01 {
    public static void main(String[] args) throws Exception {
        // 添加Jar文件 下载驱动  ==> mvn

        // URL  用户  密码   jdbc:mysql:\\localhost:3306\mydb
        String url = "jdbc:phoenix:cdh-node:2181";

        // 驱动类型加载
        Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

        // 配置
        Properties properties = new Properties();
        properties.setProperty("phoenix.schema.isNamespaceMappingEnabled", "true");

        // 建立连接
        Connection connection = DriverManager.getConnection(url, properties);

        // 创建预执行对象
        // select * from "intct86"."t10"
        PreparedStatement preparedStatement = connection.prepareStatement("select id,name,age from \"intct86\".\"t10\"");

        // 发送，并执行SQL
        ResultSet resultSet = preparedStatement.executeQuery();

        // 输出结果
        while (resultSet.next()) {
            String id = resultSet.getString("id");
            String name = resultSet.getString("name");
            String age = resultSet.getString("age");
            System.out.println("id = " + id + "; name = " + name + "; age = " + age);
        }

        // 释放资源
        resultSet.close();
        preparedStatement.close();
        connection.close();
    }
}
